package com.koala.aideddevsystemmodule.modules.idempotent.controller;

import com.koala.aideddevsystemmodule.modules.idempotent.entity.IdempotentEntity;
import com.koala.aideddevsystemmodule.modules.idempotent.service.IdempotentService;
import com.koala.aideddevsystemmodule.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 幂等性
 * Create by koala on 2022-08-21 16:35:28
 */
@RestController
@RequestMapping("/idempotent")
public class IdempotentController {

    @Autowired
    private IdempotentService idempotentService;

    /**
     * 使用redis实现幂等性
     */
    @RequestMapping("/idempotentSaveByRedis")
    public R idempotentSaveByRedis(@RequestBody IdempotentEntity idempotent) {
        Boolean aBoolean = idempotentService.idempotentSaveByRedis(idempotent);

        return R.ok().setData(aBoolean);
    }

    /**
     * 使用数据库去重表实现幂等性
     */
    @RequestMapping("/idempotentSaveBySqlTable")
    public R idempotentSaveBySqlTable(@RequestBody IdempotentEntity idempotent) {
        Boolean aBoolean = idempotentService.idempotentSaveBySqlTable(idempotent);

        return R.ok().setData(aBoolean);
    }

}
